package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.queryparam.NursingLevelQueryParam;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理有关接口")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 分页查询
     *
     * @param nlqp
     * @return
     */
    @GetMapping("/listByPage")
    @ApiOperation("分页查询护理等级")
    public ResponseResult<PageResponse<NursingLevelVo>> getPage(NursingLevelQueryParam nlqp) {

        PageResponse<NursingLevelVo> result = nursingLevelService.getPage(nlqp);

        log.info("数据库查询的数据:{}",result);

        return ResponseResult.success(result);
    }

    /**
     * 新增护理等级
     *
     * @param nld
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation("新增护理等级")
    public ResponseResult addNursingLevel(@RequestBody NursingLevelDto nld) {
        nursingLevelService.addNursingLevel(nld);

        return ResponseResult.success();
    }

    /**
     * 回显
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级")
    public ResponseResult getByIdNursingLevel(@PathVariable Integer id) {

        NursingLevelVo nlv = nursingLevelService.getByIdNursingLevel(id);

        return ResponseResult.success(nlv);
    }

    /**
     * 修改护理等级
     *
     * @param nld
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("修改护理等级")
    public ResponseResult updateNursingLevel(@RequestBody NursingLevelDto nld) {

        nursingLevelService.updateNursingLevel(nld);


        return ResponseResult.success();
    }

    /**
     * 启用禁用
     *
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用护理等级")
    public ResponseResult statusNursingLevel(@PathVariable Integer id, @PathVariable Integer status) {

        nursingLevelService.statusNursingLevel(id, status);

        return ResponseResult.success();
    }

    /**
     * 删除护理等级
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除护理等级")
    public ResponseResult deleteNursingLevel(@PathVariable Integer id) {

        nursingLevelService.deleteNursingLevel(id);

        return ResponseResult.success();
    }

    /**
     * 查询所有护理等级
     *
     * @return
     */
    @GetMapping("/listAll")
    @ApiOperation("查询所有护理等级")
    public ResponseResult allList() {

        List<NursingLevelVo> nlvList = nursingLevelService.allList();

        return ResponseResult.success(nlvList);
    }

}
